
/*-------------------------------------------------------------------
								PART 1: 
	        Start .do file with the following commands
-------------------------------------------------------------------*/

	* This command clears out all data in memory
	capture drop _all

	/*The command ``capture log close'' will close a log if any is open
	and do nothing if no log is open. (The word capture means that
	Stata should not complain if there is no log open to close. */
	capture log close

	*set more off tells Stata not to pause or display the more message
	set more off

/*-------------------------------------------------------------------
								PART 2: 
	       Set up workspace, create log file, get data
-------------------------------------------------------------------*/
	
*change the following line to the path to your working directory (where your .do and .dta files are)
cap cd "your file path here"

*open a log file. This will save everything from your output window into a text document. 
log using ./data_processing, text replace 

*load your data
use "your data path and file here", clear

/*-------------------------------------------------------------------
								PART 3: 
	                      Set up variables
-------------------------------------------------------------------*/	

** Set up variables
global IV1 "population edu_citizen_ten_thousand sec_industry i.superior_dummy l.gdpg_change_social_above l.so2_social_above_reversed"
global IV2 "l.gdpg_social_below_reversed"
global IV3 "l.so2_social_below_reversed"
global IV4 "c.l.gdpg_social_below_reversed#c.l.so2_social_below_reversed"
global IV5 "c.l.gdpg_change_social_above#c.l.so2_social_below_reversed"
global IV6 "c.l.gdpg_social_below_reversed#c.l.so2_social_above_reversed"

** generate sample based on regression (for consistent number of obs across different models)
xtset citycode year
quiet glm proportion_female $IV1 $IV2 $IV3 i.year i.citycode,family(binomial) link(logit) vce(robust)
gen sample = e(sample)


/*-------------------------------------------------------------------
								PART 4: 
	                Generate tables and graphs
-------------------------------------------------------------------*/

** Table 1 Summary Statistics
sum2docx proportion_female gdpg_social_below_reversed gdpg_change_social_above so2_social_below_reversed so2_social_above_reversed ///
population edu_citizen_ten_thousand sec_industry superior_dummy if sample == 1 using ./06_tables/descriptive_statistics.docx, ///
replace stats(N mean(%9.3f) sd min(%9.3g) median(%9.3g) max(%9.0g)) 

** Figure 2 Average Proportions of Women in Top Management in China from 2010-2018 
bys year: egen mean_prop_female = mean(proportion_female)
bys year: egen mean_female_mayor = mean(female_mayor)


twoway ///
	(area  mean_prop_female year, lcolor(gs2) color(gs2) lwidth(none) fintensity(inten20)) ///
	(area  mean_female_mayor year, lcolor(gs8) color(gs7) fintensity(inten5)) ///
	, ///
	    xtitle("Year")  ///
		xlabel(, nogrid) ///
        ytitle("Women's proportion in leadership positions")       ///
		ylabel(0(0.03)0.15, angle(horizontal) nogrid) ///
		legend(order(1 "Women in TMTs" 2 "Women as mayor" ))

		
graph export ./women_representation.tif, replace 




* Table 2 The Impact of Performance Relative to Social Aspirations on the Proportion of Women in TMTs
xtset citycode year

quiet glm proportion_female $IV1 i.year i.citycode if sample==1,family(binomial) link(logit) vce(robust)
est store glm1
quiet glm proportion_female $IV1 $IV2 $IV3  i.year i.citycode if sample==1,family(binomial) link(logit) vce(robust)
est store glm2
quiet glm proportion_female $IV1 $IV2 $IV3 $IV4  i.year i.citycode if sample==1,family(binomial) link(logit) vce(robust)
est store glm3
quiet glm proportion_female $IV1 $IV2 $IV3 $IV5 $IV6 i.year i.citycode if sample==1,family(binomial) link(logit) vce(robust)
est store glm4
quiet glm proportion_female $IV1 $IV2 $IV3 $IV4 $IV5 $IV6 i.year i.citycode if sample==1,family(binomial) link(logit) vce(robust)
est store glm5
est table glm1 glm2 glm3 glm4 glm5, b(%6.3f) star(0.1 0.05 0.01)

reg2docx glm1 glm2 glm3 glm4 glm5 using ./regression.docx, b(%9.3f)  p(%6.3f) title("Table 2") replace



	
*Figure 4 Interaction Effects for Unambiguous Failure on the Proportion of Women in TMTs
est restore glm3			  

margins,dydx(l.gdpg_social_below_reversed) at(l.so2_social_below_reversed=(0 (1) 3 4.3)) 
marginsplot, ///
		xtitle("The negative gap between environmental performance and social aspirations")  ///
			  xlabel(0 0.2 1 2 3 4.3, nogrid angle(25)) ///
              ytitle("Effects on predicted mean proportion of women in TMTs", height(3) size(*0.7))       ///
              ylabel(0(0.005)0.02, angle(horizontal) nogrid) ///
			  legend(off)   ///
			  yline(0, lc(black%15)) ///
              title("Average marginal effect of economic performance below social aspirations with 95% CIs", size(*0.7)) ///
			  plotopts(lcolor(gs8) mcolor(gs8)) ciopt(recast(rline) lcolor(black%60) lpattern(shortdash) lwidth(*0.5) fcolor(none)) ///
			  addplot(hist so2_social_below_reversed, yaxis(2) yscale(alt axis(2))  fcolor(none) lc(black%25))


graph export ./consistent_below_social.tif, replace 



			 
*Figure 5 Interaction Effects for Ambiguous Feedback on the Proportion of Women in TMTs
est restore glm4

margins,dydx(l.gdpg_change_social_above) at(l.so2_social_below_reversed=(0 0.1 (1) 4 4.3)) 
marginsplot, ///
			  xtitle("The negative gap between environmental performance and social aspirations")  ///
			  xlabel(0 0.1 1 2 3 4.3, nogrid angle(25)) ///
              ytitle("Effects on predicted mean proportion of women in TMTs")       ///
              ylabel(-0.20(0.05)0, angle(horizontal) nogrid) ///
			  legend(off)   ///
			  yline(0, lc(black%15)) ///
              title("Average marginal effect of economic performance above social aspirations with 95% CIs", size(*0.7)) ///
			  plotopts(lcolor(gs8) mcolor(gs8)) ciopt(recast(rline) lcolor(black%60) lpattern(shortdash) lwidth(*0.5) fcolor(none)) ///
			  addplot(hist so2_social_below_reversed, yaxis(2) yscale(alt axis(2)) fcolor(none) lc(black%25))
			
graph export ./social_GDP_above_SO2_below.tif, replace


*** END OF FILE ***
